home *** CD-ROM | disk | FTP | other *** search
- /**\
- |**| =====================================================================
- |**|
- |**| QDGX shell misc.c
- |**|
- |**| This file contains utility and menu handling routines for
- |**| the QuickDraw GX shell program.
- |**|
- |**| ©1992-1994 Apple Computer, Inc.
- |**| All rights reserved.
- |**|
- |**| =====================================================================
- \**/
-
-
- #include "QDGX shell.h"
- #include <GXLayout.h>
- #include "LayoutLibrary.h"
- #include "FontMenuLibrary.h"
-
-
-
- /**\
- |**| ---------------------------------------------------------------------
- |**| DoMenuCommand()
- |**| This routine handles the dispatching of our menu requests.
- |**| ---------------------------------------------------------------------
- \**/
- void DoMenuCommand (long menuResult)
- {
- short menuID;
- short menuItem;
- Str255 daName;
- OSErr err;
- gxDialogResult result;
-
- menuID = menuResult >>16;
- menuItem = menuResult & 0x0000ffff;
-
- switch (menuID)
- {
- case mApple:
- switch (menuItem)
- {
- case iAbout: /* display About box */
- NoteAlert(rAboutBoxID,nil);
- break;
-
- default: /* handle DA selection */
- GetItem(GetMHandle(mApple), menuItem, daName);
- OpenDeskAcc(daName);
- break;
- }
- break;
-
-
- case mFile:
- switch (menuItem)
- {
- case iNew: /* create new window */
- err = DoCreateNew();
- break;
-
- case iOpen: /* open saved window */
- break;
-
- case iClose: /* close front window */
- DoDispose(FrontWindow());
- break;
-
- case iSave: /* save front window */
- break;
-
- case iPageSetup: /* perform page setup */
- HiliteMenu(0);
- err = DoFormat(FrontWindow(), &result);
- break;
-
- case iPrintOne: /* perform print-one */
- err = DoPrintOne(FrontWindow());
- break;
-
- case iPrint: /* perform print */
- HiliteMenu(0);
- err = DoPrinting(FrontWindow());
- break;
-
- case iQuit:
- gQuitting = true;
- break;
- }
- break;
-
-
- case mEdit:
- switch(menuItem)
- {
- case iCut:
- LayoutEditCut( GetDocLEHandle(FrontWindow()) );
- break;
-
- case iCopy:
- LayoutEditCopy( GetDocLEHandle(FrontWindow()) );
- break;
-
- case iPaste:
- LayoutEditPaste( GetDocLEHandle(FrontWindow()) );
- break;
-
- case iClear:
- LayoutEditClear( GetDocLEHandle(FrontWindow()) );
- break;
- }
- break;
-
- case nestingMenuID:
- switch (menuItem)
- {
- case nestCommand:
- LayoutEditIncrementLevel( GetDocLEHandle(FrontWindow()) );
- break;
-
- case unnestCommand:
- LayoutEditDecrementLevel( GetDocLEHandle(FrontWindow()) );
- break;
-
- default:
- LayoutEditSetLevel( GetDocLEHandle(FrontWindow()), menuItem - zeroCommand);
- break;
- }
- break;
-
- case fontMenuID:
- default:
- {
- Boolean ok;
- gxStyle menuStyle;
- static short first = true;
-
- menuStyle = GXNewStyle();
- ok = DoHierFontMenuCommandStyle(menuResult, fontMenuID, menuStyle, noMatching);
- if (ok)
- {
- GXSetStyleTextSize(menuStyle, ff(30));
- LayoutEditSetStyle( GetDocLEHandle(FrontWindow()), menuStyle);
- }
- GXDisposeStyle(menuStyle);
-
- }
- break;
-
- }
- HiliteMenu(0);
- }
-
-
- /**\
- |**| ---------------------------------------------------------------------
- |**| GetDocShape()
- |**| This utility routine returns the page contents shape
- |**| attached to a window's document.
- |**| ---------------------------------------------------------------------
- \**/
- gxShape GetDocShape (WindowPtr wind)
- {
- TH_Doc doc;
- gxShape docPage = nil;
-
- if ( wind != NULL )
- {
- doc = (TH_Doc) GetWRefCon(wind);
- docPage = (*doc)->docPage;
- }
-
- return docPage;
- }
-
-
- /**\
- |**| ---------------------------------------------------------------------
- |**| GetDocJob()
- |**| This utility routine returns the print job attached to a window's document.
- |**| ---------------------------------------------------------------------
- \**/
- gxJob GetDocJob (WindowPtr wind)
- {
- TH_Doc doc;
- gxJob docJob = nil;
-
- if ( wind != NULL )
- {
- doc = (TH_Doc) GetWRefCon(wind);
- docJob = (*doc)->docJob;
- }
-
- return docJob;
- }
-
-
- /**\
- |**| ---------------------------------------------------------------------
- |**| GetDocLEHandle()
- |**| This utility routine returns the current LayoutEditHandle structure
- |**| attached to a window's document.
- |**| ---------------------------------------------------------------------
- \**/
- LayoutEditHandle GetDocLEHandle (WindowPtr wind)
- {
- TH_Doc doc;
- LayoutEditHandle docLEHandle = nil;
-
- if ( wind != NULL )
- {
- doc = (TH_Doc) GetWRefCon(wind);
- docLEHandle = (*doc)->docLEHandle;
- }
-
- return docLEHandle;
- }
-
-
- /**\
- |**| ---------------------------------------------------------------------
- |**| MyStrLength()
- |**| This function takes the length of a C-style string quickly without
- |**| requiring an ANSI library to be linked in.
- |**| ---------------------------------------------------------------------
- \**/
- short MyStrLength (char *s)
- {
- short len;
-
- for (len = 0; *s++ != 0; len++) ;
- return len;
- }
-
-